home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / CNews / Source / conf / dowhatever.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-25  |  1.2 KB  |  70 lines

  1. /*
  2.  * the main program for do(statfs, ustat, ultrix, ...)
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <sys/types.h>
  8.  
  9. long bperi = 1000000000L;    /* how many bytes per inode? */
  10.  
  11. int debug = 0;
  12. char *progname;
  13.  
  14. extern void error(), exit();
  15.  
  16. /*
  17.  - main - parse arguments and handle options
  18.  */
  19. main(argc, argv)
  20. int argc;
  21. char *argv[];
  22. {
  23.     int c;
  24.     int errflg = 0;
  25.     extern int optind;
  26.     extern char *optarg;
  27.     long process();
  28.     extern long atol();
  29.     extern double atof();
  30.     register long n;
  31.  
  32.     progname = argv[0];
  33.  
  34.     while ((c = getopt(argc, argv, "e:d")) != EOF)
  35.         switch (c) {
  36.         case 'e':    /* Estimated bytes/inode. */
  37.             bperi = atol(optarg);
  38.             break;
  39.         case 'd':    /* Debugging. */
  40.             debug++;
  41.             break;
  42.         case '?':
  43.         default:
  44.             errflg++;
  45.             break;
  46.         }
  47.     if (errflg || optind != argc-4 || !num(argv[optind]) ||
  48.                         !num(argv[optind+2]) ||
  49.                         !num(argv[optind+3])) {
  50.         fprintf(stderr, "usage: %s [-e estsize]", progname);
  51.         fprintf(stderr, "filesize fileonfs wantspace wantinodes\n");
  52.         exit(2);
  53.     }
  54.  
  55.     n = process((long)atof(argv[optind]), argv[optind+1],
  56.             atol(argv[optind+2]), atol(argv[optind+3]), bperi);
  57.     printf("%ld\n", n);
  58.     exit(0);
  59. }
  60.  
  61. /*
  62.  - num - is a string numeric?
  63.  */
  64. int                /* predicate */
  65. num(s)
  66. char *s;
  67. {
  68.     return(strspn(s, "0123456789.eE+-") == strlen(s));
  69. }
  70.